package com.hsav.kcxb.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.widget.TextView;

/**
 * Created by zhao on 2017/3/12.
 */

public class SideBar extends View {

    private TextView mTextDialog;
    public static final String[] CAPTIONS = {
            "A", "B", "C", "D", "E", "F", "G", "H", "I",
            "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V",
            "W", "X", "Y", "Z", "#"
    };

    private Paint mPaint = new Paint();
    private int mChoose = -1;

    public SideBar(Context context) {
        super(context);
    }

    public SideBar(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public SideBar(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public void setTextView(TextView textDialog) {
        this.mTextDialog = textDialog;
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        int height = getHeight();
        int width = getWidth();
        int singleHeight = height / CAPTIONS.length;
        for (int i = 0; i < CAPTIONS.length; i++) {
            mPaint.setColor(Color.rgb(33,65,98));
            mPaint.setTypeface(Typeface.DEFAULT_BOLD);
            mPaint.setAntiAlias(true);
            mPaint.setTextSize(20);
            if(i==mChoose){
                mPaint.setColor(Color.parseColor("#3399ff"));
                mPaint.setFakeBoldText(true);
            }
            float xPos = width/2-mPaint.measureText(CAPTIONS[i])/2;
            float yPos = singleHeight*i+singleHeight;
            canvas.drawText(CAPTIONS[i],xPos,yPos,mPaint);
            mPaint.reset();
        }
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent event) {
        final int action = event.getAction();
        final float y = event.getY();
        return super.dispatchTouchEvent(event);
    }
}
